<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/10
 * Time: 16:22
 */
namespace app\admin\controller;
class Reply extends Check{
    public function replyList(){
        $article = new \app\data\Data('ask');
        $where = 'a.id > 0';
        $get = input('param.');
        if(!empty($get['search'])){
            $where .= " and title like '%{$get['search']}%'";
            $this->assign('search',$get['search']);
        }
        $list = $article->page($where,"create_time desc",config('paginate.list_rows'),$get,[],"*",$get['page']);
        return view('replyList',['list'=>$list->items(),'page'=>$list->render()]);
    }

    public function replySave(){
        try{
            $id = input('param.id');
            $ask = new \app\data\Data('ask');
            $one = $ask->find(['id'=>$id]);
            if(request()->isPost()){
                $post = input('param.');
                $post['is_reply'] = 1;
                $post['reply_time'] = time();
                if($ask->updateData($post)){
                    return self::formatSuccessResult();
                }
            }
        }catch(\Exception $e){
            return self::formatResult($e->getCode(),$e->getMessage());
        }
        return view('replySave',[
            'one'=>$one
        ]);
    }
}